package com.secsys.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.secsys.model.TbSysRole;
import com.secsys.model.TbSysRoleResource;
import com.secsys.service.RoleResourceService;

public class RoleResourceServiceImpl extends ServiceImpl<TbSysRoleResource, Integer> implements RoleResourceService {

	private RoleServiceImpl roleService;
	
	@Override
	public List<TbSysRoleResource> queryByRoleId(Integer roleId) {
		// TODO Auto-generated method stub
		List<TbSysRoleResource> roleResources = new ArrayList<TbSysRoleResource>();
		//TbSysRole sysRole = new TbSysRole();
		//sysRole = roleService.findById(roleId);
		roleResources = this.dao.find("from TbSysRoleResource where tbSysRole.id=?", new Object[]{roleId});
		if(roleResources!=null && roleResources.size()>0){
			return roleResources;
		}else{
			return null;
		}
	}
	
	@Override
	public List<TbSysRoleResource> queryByResourceId(Integer resourceId) {
		// TODO Auto-generated method stub
		List<TbSysRoleResource> roleResources = new ArrayList<TbSysRoleResource>();
		//TbSysRole sysRole = new TbSysRole();
		//sysRole = roleService.findById(roleId);
		roleResources = this.dao.find("from TbSysRoleResource where tbSysResource.id=?", new Object[]{resourceId});
		if(roleResources!=null && roleResources.size()>0){
			return roleResources;
		}else{
			return null;
		}
	}

	public RoleServiceImpl getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleServiceImpl roleService) {
		this.roleService = roleService;
	}

	@Override
	public TbSysRoleResource findRoleResourceByRoleIdAndResourceId(
			Integer roleId, Integer resourceId) {
		// TODO Auto-generated method stub
		List<TbSysRoleResource> roleResources = this.dao.find("from TbSysRoleResource where tbSysRole.id=? and tbSysResource.id=?", new Object[]{roleId,resourceId});
		if(roleResources!=null && roleResources.size()>0){
			return roleResources.get(0);
		}else{
			return null;
		}
	}


}
